package com.project.biz.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.project.biz.CmsRecoveryMemberEvaBiz;
import com.project.entity.CmsRecoveryMemberEva;
import com.project.mapper.CmsRecoveryMemberEvaMapper;
import com.project.pojo.model.RecoveryMemberEvaModel;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Description: 回收员评论业务层接口实现类
 * @Author: zhuchi
 * @CreateDate: 2020/11/16 17:12
 * @Version: 1.0
 */
@Service
public class CmsRecoveryMemberEvaBizImpl extends ServiceImpl<CmsRecoveryMemberEvaMapper, CmsRecoveryMemberEva> implements CmsRecoveryMemberEvaBiz {

    /**
     * 添加回收员评论
     * @param recoveryMemberEvaModel
     * @param recoveryMemberId 回收员ID
     * @param userId 评论用户ID
     * @return
     */
    public int addRecoveryMemberEva(RecoveryMemberEvaModel recoveryMemberEvaModel, Long recoveryMemberId, Long userId){
        CmsRecoveryMemberEva recoveryMemberEva = new CmsRecoveryMemberEva();
        BeanUtils.copyProperties(recoveryMemberEvaModel, recoveryMemberEva);
        recoveryMemberEva.setRecoveryMemberId(recoveryMemberId);
        recoveryMemberEva.setCreateTime(new Date());
        recoveryMemberEva.setCreateUser(userId);
        recoveryMemberEva.setStatus(1);
        return this.baseMapper.insert(recoveryMemberEva);
    }

    /**
     * 根据回收订单获取评论信息
     * @param recoveryOrderId
     * @return
     */
    public CmsRecoveryMemberEva getEvaByRecoveryOrderId(Long recoveryOrderId){
        QueryWrapper<CmsRecoveryMemberEva> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("recovery_order_id", recoveryOrderId);
        CmsRecoveryMemberEva recoveryMemberEva = this.baseMapper.selectOne(queryWrapper);
        return recoveryMemberEva;
    }

    /**
     * 获取回收员平均评分
     * @param recoveryMemberId
     * @return
     */
    public int getRecoverMemberAvgScore(Long recoveryMemberId){
        return this.baseMapper.getRecoverMemberAvgScore(recoveryMemberId);
    }

}
